/**
eg:
<modal maskClose></modal>
 */
<template>
  <transition name="modal">
    <div class="modal-mask" @click="mask()" v-show="c.show">
      <div class="modal-wrapper">
        <div class="modal-container" @click.stop>
          <div v-if="!hideClose" class="modal-close flex-center iconfont" @click="close">
            &#215;
          </div>
          <slot>
          </slot>
        </div>
      </div>
    </div>
  </transition>
</template>
<script>
export default {
  name: 'modal',
  props: {
    c: {
      type: Object,
      default: () => {
        return {}
      },
    },
    hideClose: {
      type: Boolean,
      default: false,
    },
    maskClose: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {}
  },
  computed: {},
  methods: {
    close() {
      this.c.show = false
      this.$emit('close')
    },
    // 点遮罩关闭
    mask() {
      if (this.maskClose) {
        this.close()
      }
    }
  },
  mounted() {
  },
  beforeDestroy() {
  },
  destroyed() {
  }
}
</script>
<style lang="scss">
.modal-mask {
  position: fixed;
  z-index: 9998;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: table;
  transition: opacity 0.3s ease;
}

.modal-wrapper {
  display: table-cell;
  vertical-align: middle;
}

.modal-container {
  position: relative;
  width: 300px;
  margin: 0px auto;
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
  transition: all 0.3s ease;
  font-family: Helvetica, Arial, sans-serif;
}

.modal-default-button {
  float: right;
}

.modal-enter {
  opacity: 0;
}

.modal-leave-active {
  opacity: 0;
}

.modal-enter .modal-container,
.modal-leave-active .modal-container {
  -webkit-transform: scale(1.1);
  transform: scale(1.1);
}

.modal-close {
  position: absolute;
  right: -15px;
  top: -15px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: #f56c6c;
  font-size: 28px;
  font-weight: bold;
  color: #fff;
  display: flex;
  justify-content: center;
  align-content: center;
  align-items: center;
}
</style>
